<?php
class Web_model extends CI_Model{
	function __construct(){
		parent::__construct();
	}

	function getAllInfo(){
		$this->db->select('*');
		$this->db->order_by('id_info', 'DESC');
		$query = $this->db->get('info');
		
		return $query->result_array();
	}

	function getBerita(){
		$this->db->select('*');
		$this->db->order_by('id_berita', 'DESC');
		$this->db->limit(3,3);
		$query = $this->db->get('berita');
		
		return $query->result_array();
	}

	function getPhoto($NIM){
		return "http://www.amikom.ac.id/public/fotomhs/20".substr($NIM, 0,2)."/".$NIM.".jpg";
	}
	
	function getBeritaByPage($perPage, $offset){
		$this->db->select('*');
		$this->db->order_by('id_berita', 'DESC');
		$this->db->limit($perPage, $offset);
		$query = $this->db->get('berita');
		
		return $query->result_array();
	}

	function getAgendaByPage($perPage, $offset){
		$this->db->select('*');
		$this->db->order_by('id_agenda', 'DESC');
		$this->db->limit($perPage, $offset);
		$query = $this->db->get('agenda');
		
		return $query->result_array();
	}
	
	function getAllBerita(){
		$this->db->select('*');
		$this->db->order_by('id_berita', 'DESC');
		$query = $this->db->get('berita');
		
		return $query->result_array();
	}
	
	function getAllAgenda(){
		$this->db->select('*');
		$this->db->order_by('id_agenda', 'DESC');
		$query = $this->db->get('agenda');
		
		return $query->result_array();
	}
	
	function getLimitAgenda(){
		$this->db->select('*');
		$this->db->order_by('id_agenda', 'DESC');
		$this->db->limit(1);
		$query = $this->db->get('agenda');
		
		return $query->result_array();
	}
	
	function getDetailBerita($id){
		$this->db->select('*');
		$this->db->where('id_berita',$id);
		$query = $this->db->get('berita');
		
		return $query->result_array();
	}
	
	function getDetailAgenda($id){
		$this->db->select('*');
		$this->db->where('id_agenda',$id);
		$query = $this->db->get('agenda');
		
		return $query->result_array();
	}
	
	function getDetailInfo($id){
		$this->db->select('*');
		$this->db->where('id_info',$id);
		$query = $this->db->get('info');
		
		return $query->result_array();
	}
	
	function getDivisi(){
		$this->db->select('*');
		$this->db->order_by('id_divisi', 'DESC');
		$query = $this->db->get('divisi');
		
		return $query->result_array();
	}
	
	function cariMember($nim){
		//$this->db->select('*');
		//$this->db->where('nim', $nim);
		$query = $this->db->query("select * from member a join divisi b on a.id_divisi=b.id_divisi where a.nim='".$nim."' order by a.nim");
		//$query = $this->db->get('member');
		//return $query;
		return $query->result_array();
	}
	
	function getElearning(){
		$this->db->select('*');
		$this->db->order_by('id_materi', 'DESC');
		$query = $this->db->get('elearning');
		
		return $query->result_array();
	}

	function getElearningDesktop(){
		$this->db->select('*');
		$this->db->order_by('id_materi', 'DESC');
		$this->db->where('id_divisi','1');
		$query = $this->db->get('elearning');
		
		return $query->result_array();
	}

	function getElearningWeb(){
		$this->db->select('*');
		$this->db->order_by('id_materi', 'DESC');
		$this->db->where('id_divisi','2');
		$query = $this->db->get('elearning');
		
		return $query->result_array();
	}

	function getElearningJaringan(){
		$this->db->select('*');
		$this->db->order_by('id_materi', 'DESC');
		$this->db->where('id_divisi','3');
		$query = $this->db->get('elearning');
		
		return $query->result_array();
	}

	function getElearningHardware(){
		$this->db->select('*');
		$this->db->order_by('id_materi', 'DESC');
		$this->db->where('id_divisi','4');
		$query = $this->db->get('elearning');
		
		return $query->result_array();
	}

	
	function insert_pildiv($nim,$nama,$hp,$kelas,$jurusan,$sekolah,$jur_sekolah,$divisi,$laptop,$materi,$harapan){
		$data = array(
			'nim'  => $nim,
			'nama' => $nama,
			'hp' => $hp,
			'kelas' => $kelas,
			'jurusan' => $jurusan,
			'sekolah' => $sekolah,
			'asaljurusan' => $jur_sekolah,
			'id_divisi' => $divisi,
			'laptop' => $laptop,
			'materi' => $materi,
			'harapan' => $harapan
		);
		
		$this->db->insert('member', $data);
		if ($this->db->affected_rows() == 1) {
			return TRUE;
		}
		return FALSE;
	}
		
	function getTable($perPage = 0, $offset = 0, $primary, $tabel) {
		$this->db->select('*');
		$this->db->order_by($primary, 'DESC');
		$this->db->limit($perPage, $offset);
		$query = $this->db->get($tabel);
		
		return $query->result_array();
	
	}
	

}

?>